
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>自定义磁盘镜像 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../ysyx/FangCore/1单周期CPU.html" />
    
    
    <link rel="prev" href="gem5_fs.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">BoomV3</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../BoomCode/chipyard-install.html">
            
                <a href="../BoomCode/chipyard-install.html">
            
                    
                    Chipyard 1.8.0安装教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../BoomCode/boom-debug.html">
            
                <a href="../BoomCode/boom-debug.html">
            
                    
                    Boom调试【更新中】
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">论文阅读</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../paper_read/prefetch-guard.html">
            
                <a href="../paper_read/prefetch-guard.html">
            
                    
                    Prefetch-guard
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Gem5 学习</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="gem5_fs.html">
            
                <a href="gem5_fs.html">
            
                    
                    X86 全系统模式模拟
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.2" data-path="custom_disk_img.html">
            
                <a href="custom_disk_img.html">
            
                    
                    自定义磁盘镜像
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">一生一芯FangCore实现</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../ysyx/FangCore/1单周期CPU.html">
            
                <a href="../ysyx/FangCore/1单周期CPU.html">
            
                    
                    单周期CPU实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../ysyx/FangCore/2五级流水.html">
            
                <a href="../ysyx/FangCore/2五级流水.html">
            
                    
                    顺序五级流水CPU设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../ysyx/FangCore/3乘除法器.html">
            
                <a href="../ysyx/FangCore/3乘除法器.html">
            
                    
                    乘除法功能单元
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../ysyx/FangCore/4AXI4总线.html">
            
                <a href="../ysyx/FangCore/4AXI4总线.html">
            
                    
                    AXI4总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../ysyx/FangCore/5高速缓存Cache.html">
            
                <a href="../ysyx/FangCore/5高速缓存Cache.html">
            
                    
                    高速缓存Cache设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../ysyx/FangCore/6中断异常.html">
            
                <a href="../ysyx/FangCore/6中断异常.html">
            
                    
                    简单的中断异常支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="../ysyx/FangCore/7分支预测器.html">
            
                <a href="../ysyx/FangCore/7分支预测器.html">
            
                    
                    分支预测器
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >自定义磁盘镜像</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x81EA;&#x5B9A;&#x4E49;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#xFF0C;&#x4F7F;&#x7528;gem5-fs&#x6A21;&#x5F0F;&#x8FD0;&#x884C;&#x7279;&#x5B9A;&#x7684;&#x7A0B;&#x5E8F;">&#x81EA;&#x5B9A;&#x4E49;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#xFF0C;&#x4F7F;&#x7528;Gem5 FS&#x6A21;&#x5F0F;&#x8FD0;&#x884C;&#x7279;&#x5B9A;&#x7684;&#x7A0B;&#x5E8F;</h1>
<h2 id="0&#x3001;&#x53C2;&#x8003;&#x8D44;&#x6599;">0&#x3001;&#x53C2;&#x8003;&#x8D44;&#x6599;</h2>
<ul>
<li><a href="https://gem5bootcamp.github.io/gem5-bootcamp-env/modules/using%20gem5/full-system/" target="_blank">gem5bootcamp-using gem5 for full system simulatior</a></li>
<li><a href="https://www.gem5.org/documentation/general_docs/fullsystem/disks" target="_blank">gem5 documents creating disk images for full system mode</a></li>
<li><a href="https://www.gem5.org/documentation/gem5art/main/disks" target="_blank">gem5art: disk images</a></li>
</ul>
<h2 id="1&#x3001;&#x955C;&#x50CF;&#x6587;&#x4EF6;--packer">1&#x3001;&#x955C;&#x50CF;&#x6587;&#x4EF6; &amp; Packer</h2>
<p>&#x4E3A;&#x4E86;&#x5728;gem5&#x4E2D;&#x8FD0;&#x884C;&#x81EA;&#x5DF1;&#x7684;&#x7A0B;&#x5E8F;&#xFF0C;&#x9700;&#x8981;&#x51C6;&#x5907;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x548C;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#x3002;&#x521B;&#x5EFA;&#x81EA;&#x5B9A;&#x4E49;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#x6709;&#x5F88;&#x591A;&#xFF08;&#x53EF;&#x4EE5;&#x53BB;&#x770B;<a href="https://www.gem5.org/documentation/general_docs/fullsystem/disks" target="_blank">gem5 documents creating disk images for full system mode</a>&#xFF09;&#xFF0C;&#x8FD9;&#x91CC;&#x4ECB;&#x7ECD;&#x5982;&#x4F55;&#x4F7F;&#x7528;Packer&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#x6620;&#x50CF;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x4F7F;&#x7528;Packer&#x548C;QEMU&#x5B9E;&#x73B0;&#x78C1;&#x76D8;&#x521B;&#x5EFA;&#x8FC7;&#x7A0B;&#x7684;&#x81EA;&#x52A8;&#x5316;&#x3002;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;QEMU&#x3002;Packer&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x66F4;&#x7B80;&#x5355;&#x7684;&#x4E0E;qemu&#x4EA4;&#x4E92;&#x7684;&#x65B9;&#x6CD5;&#xFF08;&#x4F7F;&#x7528;.json&#x811A;&#x672C;&#xFF09;&#x3002;Qemu&#x8D1F;&#x8D23;&#x5EFA;&#x7ACB;&#x865A;&#x62DF;&#x673A;&#x548C;&#x4E0E;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x7684;&#x6240;&#x6709;&#x4EA4;&#x4E92;&#xFF0C;&#x5305;&#x62EC;&#xFF1A;</p>
<ul>
<li><p>&#x5728;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x4E2D;&#x5B89;&#x88C5;Ubuntu</p>
</li>
<li><p>&#x5C06;&#x6587;&#x4EF6;&#x4ECE;&#x4E3B;&#x673A;&#x590D;&#x5236;&#x5230;&#x78C1;&#x76D8;&#x6620;&#x50CF;</p>
</li>
<li><p>&#x5B89;&#x88C5;Ubuntu&#x540E;&#xFF0C;&#x5728;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x4E0A;&#x8FD0;&#x884C;&#x811A;&#x672C;</p>
</li>
</ul>
<p>gem5 Resources&#x4E2D;&#x5C31;&#x6709;&#x5F88;&#x591A;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#xFF0C;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;NPB&#xFF08;NAS parallel benchmarks&#xFF09;&#xFF0C;&#x4F5C;&#x4E3A;&#x6F14;&#x793A;&#x4F8B;&#x5B50;&#x3002;&#x6E90;&#x7801;&#x89C1;&#xFF1A;<a href="https://github.com/gem5/gem5-resources/tree/stable/src/npb" target="_blank">https://github.com/gem5/gem5-resources/tree/stable/src/npb</a></p>
<p>&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#xFF1A;&#xFF08;&#x8BF7;&#x6CE8;&#x610F;gem5&#x6E90;&#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x4F4D;&#x7F6E;)</p>
<pre><code>npb/
  |___ gem5/                               # gem5 source code
  |
  |___ disk-image/
  |      |___ build.sh                     # The script downloading packer binary and building the disk image
  |      |___ shared/                      # Auxiliary files needed for disk creation
  |      |___ npb/
  |            |___ npb-image/             # Will be created once the disk is generated
  |            |      |___ npb             # The generated disk image
  |            |___ npb.json               # The Packer script to build the disk image
  |            |___ runscript.sh           # Executes a user provided script in simulated guest
  |            |___ post-installation.sh   # Moves runscript.sh to guest&apos;s .bashrc
  |            |___ npb-install.sh         # Compiles NPB inside the generated disk image
  |            |___ npb-hooks              # The NPB source (modified to function better with gem5).
  |
  |___ linux                               # Linux source and binary will live here
  |
  |___ README.md                           # This README file
</code></pre><h2 id="2&#x3001;&#x4F7F;&#x7528;packer&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x6587;&#x4EF6;">2&#x3001;&#x4F7F;&#x7528;Packer&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x6587;&#x4EF6;</h2>
<h3 id="21-&#x4E0B;&#x8F7D;&#x4F9D;&#x8D56;&#x3001;&#x8F6F;&#x4EF6;&#xFF1A;qemu&#x548C;packer">2.1 &#x4E0B;&#x8F7D;&#x4F9D;&#x8D56;&#x3001;&#x8F6F;&#x4EF6;&#xFF1A;QEMU&#x548C;PACKER</h3>
<p>&#x5B89;&#x88C5;Qemu</p>
<pre><code>sudo apt-get install qemu
</code></pre><p>&#x6784;&#x5EFA;m5&#xFF08;&#x5047;&#x8BBE;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x5939;&#x4E3A;src/npb/)</p>
<pre><code>git clone https://gem5.googlesource.com/public/gem5
cd gem5/util/m5
scons build/x86/out/m5
</code></pre><p>&#x67E5;&#x770B;build.sh&#x6587;&#x4EF6;&#xFF0C;&#x8BE5;&#x811A;&#x672C;&#x4E0B;&#x8F7D;packer&#x5E76;&#x6784;&#x5EFA;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x3002;&#x4E00;&#x65E6;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x6210;&#x529F;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5728; npb/npb-image/npb &#x4E0A;&#x627E;&#x5230;&#x521B;&#x5EFA;&#x7684;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6784;&#x5EFA;&#x78C1;&#x76D8;&#x786C;&#x4EF6;&#x7684;&#x5173;&#x952E;&#x4EE3;&#x7801;&#x5728;&#x7B2C;10&#x884C;&#xFF0C;packer&#x7A0B;&#x5E8F;&#x6839;&#x636E;npb/npb.json&#x6784;&#x5EFA;&#x78C1;&#x76D8;&#x6620;&#x50CF;</p>
<pre><code>PACKER_VERSION=&quot;1.7.8&quot;

if [ ! -f ./packer ]; then
    wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip;
    unzip packer_${PACKER_VERSION}_linux_amd64.zip;
    rm packer_${PACKER_VERSION}_linux_amd64.zip;
fi

./packer validate npb/npb.json
./packer build npb/npb.json
</code></pre><h3 id="22-&#x81EA;&#x5B9A;&#x4E49;packer-&#x811A;&#x672C;&#xFF08;xxxjson">2.2 &#x81EA;&#x5B9A;&#x4E49;Packer &#x811A;&#x672C;&#xFF08;XXX.json)</h3>
<h4 id="&#x2460;disk-imgjson">&#x2460;[disk-img].json</h4>
<p>&#x9ED8;&#x8BA4;&#x6253;&#x5305;&#x7A0B;&#x5E8F;&#x811A;&#x672C;&#x6A21;&#x677F;.json&#x5E94;&#x6839;&#x636E;&#x6240;&#x9700;&#x7684;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x548C;&#x6784;&#x5EFA;&#x8FC7;&#x7A0B;&#x7684;&#x53EF;&#x7528;&#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x548C;&#x8C03;&#x6574;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x9ED8;&#x8BA4;&#x6A21;&#x677F;&#x91CD;&#x547D;&#x540D;&#x4E3A; [disk-name].json&#x3002;&#x5E94;&#x4FEE;&#x6539;&#x7684;&#x53D8;&#x91CF;&#x663E;&#x793A;&#x5728; [disk-name].json &#x6587;&#x4EF6;&#x672B;&#x5C3E;&#x7684;&#x53D8;&#x91CF;&#x90E8;&#x5206;&#x4E2D;&#x3002;</p>
<p>&#x8BE5;.json&#x6587;&#x4EF6;&#x4E3B;&#x8981;&#x5305;&#x542B;&#x4E09;&#x5927;&#x90E8;&#x5206;&#xFF1A;builders&#x3001;provisioners&#x548C;provisioners&#x3002;&#x5728;&#x6784;&#x5EFA;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x65F6;&#xFF0C;&#x7528;&#x6237;&#x9700;&#x8981;&#x5C06;&#x5176;&#x6587;&#x4EF6;&#xFF08;&#x57FA;&#x51C6;&#x3001;&#x6570;&#x636E;&#x96C6;&#x7B49;&#xFF09;<strong>&#x79FB;&#x52A8;&#x5230;&#x78C1;&#x76D8;&#x6620;&#x50CF;</strong>&#x3002;&#x4E3A;&#x4E86;&#x6267;&#x884C;&#x6B64;&#x6587;&#x4EF6;&#x4F20;&#x8F93;&#xFF0C;&#x5728;&#x914D;&#x7F6E;&#x7A0B;&#x5E8F;&#x4E0B;&#x7684; [disk-name].json &#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#xFF08;&#x4E5F;&#x5C31;&#x662F;provisioners&#x90E8;&#x5206;&#xFF09;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202304121634451.png" alt="image-20230412163412266"></p>
<p>&#x4E0A;&#x9762;&#x7684;&#x793A;&#x4F8B;&#x5C06;&#x6587;&#x4EF6;&#x5171;&#x4EAB;/post_installation.sh&#x4ECE;&#x4E3B;&#x673A;&#x590D;&#x5236;&#x5230;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x4E2D;&#x7684; /home/gem5/&#x3002;&#x6B64;&#x65B9;&#x6CD5;&#x8FD8;&#x80FD;&#x591F;&#x5C06;&#x6587;&#x4EF6;&#x5939;&#x4ECE;&#x4E3B;&#x673A;&#x590D;&#x5236;&#x5230;&#x78C1;&#x76D8;&#x6620;&#x50CF;&#x3002;&#x78C1;&#x76D8;&#x542F;&#x52A8;&#x540E;&#xFF0C;&#x5C06;&#x4F1A;&#x8FD0;&#x884C;post-install.sh&#x548C;npb.sh&#x811A;&#x672C;&#xFF08;&#x8FD0;&#x884C;&#x987A;&#x5E8F;&#x6211;&#x6CA1;&#x592A;&#x641E;&#x660E;&#x767D;&#x554A;&#x554A;&#xFF09;&#x3002;&#x8FD9;&#x4E24;&#x4E2A;&#x811A;&#x672C;&#x5C06;&#x5728;&#x4E0B;&#x9762;&#x8FDB;&#x884C;&#x4ECB;&#x7ECD;&#x3002;</p>
<p>&#x8BF7;&#x52A1;&#x5FC5;&#x6CE8;&#x610F;&#xFF0C;&#x5C3E;&#x90E8;&#x659C;&#x6760;&#x4F1A;&#x5F71;&#x54CD;&#x590D;&#x5236;&#x8FC7;&#x7A0B;&#xFF08;&#x66F4;&#x591A;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#xFF09;&#x3002;&#x4EE5;&#x4E0B;&#x662F;&#x5728;&#x8DEF;&#x5F84;&#x672B;&#x5C3E;&#x4F7F;&#x7528;&#x659C;&#x6760;&#x6548;&#x679C;&#x7684;&#x4E00;&#x4E9B;&#x503C;&#x5F97;&#x6CE8;&#x610F;&#x7684;&#x793A;&#x4F8B;&#x3002;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202304121639071.png" alt="image-20230412163952037"></p>
<p>&#x8FD8;&#x9700;&#x8981;&#x66F4;&#x6539;variables&#x90E8;&#x5206;&#x3002;&#x5C06;image-name&#x66F4;&#x6539;&#x4E3A;&#x4F60;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x3002;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202304121645324.png" alt="image-20230412164520241"></p>
<h4 id="&#x2461;shared&#x6587;&#x4EF6;&#x5939;">&#x2461;shared&#x6587;&#x4EF6;&#x5939;</h4>
<p>shared&#x6587;&#x4EF6;&#x5939;&#x4E3B;&#x8981;&#x5305;&#x542B;&#x4E86;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;<code>serial-getty@.service</code>&#x548C;<code>preseed.cfg</code>(&#x7528;&#x4E8E;&#x5B89;&#x88C5; Ubuntu &#x7684;&#x9884;&#x79CD;&#x5B50;&#x914D;&#x7F6E;)&#x3002;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#x4E0D;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x6539;&#x52A8;&#xFF0C;&#x662F;&#x5FC5;&#x8981;&#x7684;&#xFF0C;&#x5728;&#x4F60;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7528;&#x4E8E;&#x6784;&#x5EFA;&#x78C1;&#x76D8;&#x5370;&#x8C61;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x4E5F;&#x9700;&#x8981;&#x5305;&#x542B;&#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#x3002;</p>
<h4 id="&#x2462;-post-installationsh&#xFF1A;&#x5B89;&#x88C5;-ubuntu-&#x540E;&#x6267;&#x884C;&#x7684;&#x901A;&#x7528;-shell-&#x811A;&#x672C;">&#x2462; post-installation.sh&#xFF1A;&#x5B89;&#x88C5; Ubuntu &#x540E;&#x6267;&#x884C;&#x7684;&#x901A;&#x7528; shell &#x811A;&#x672C;</h4>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash
</span>
<span class="hljs-comment"># Copyright (c) 2020 The Regents of the University of California.</span>
<span class="hljs-comment"># SPDX-License-Identifier: BSD 3-Clause</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">&apos;Post Installation Started&apos;</span>

mv /home/gem5/serial-getty@.service /lib/systemd/system/

mv /home/gem5/m5 /sbin
ln <span class="hljs-_">-s</span> /sbin/m5 /sbin/gem5

<span class="hljs-comment"># copy and run outside (host) script after booting</span>
cat /home/gem5/runscript.sh &gt;&gt; /root/.bashrc

<span class="hljs-built_in">echo</span> <span class="hljs-string">&apos;Post Installation Done&apos;</span>
</code></pre>
<p>/home/gem5&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x90FD;&#x662F;&#x6211;&#x4EEC;&#x5728;.json&#x4E2D;&#x6307;&#x5B9A;&#x5E76;&#x901A;&#x8FC7;qemu&#x4E0A;&#x4F20;&#x5230;&#x78C1;&#x76D8;&#x4E0A;&#x7684;&#x3002;&#x5982;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202304121651473.png" alt="image-20230412165109437"></p>
<p>&#x67E5;&#x770B;runscript.sh&#x7684;&#x5185;&#x5BB9;:</p>
<p>&#x5176;&#x4E2D;&#x91CD;&#x8981;&#x7684;&#x4E00;&#x4E2A;&#x5185;&#x5BB9;&#x5C31;&#x662F;&#x7B2C;6&#x884C;&#x3002;</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/sh
</span>
<span class="hljs-comment"># Copyright (c) 2020 The Regents of the University of California.</span>
<span class="hljs-comment"># SPDX-License-Identifier: BSD 3-Clause</span>

m5 readfile &gt; script.sh
<span class="hljs-keyword">if</span> [ <span class="hljs-_">-s</span> script.sh ]; <span class="hljs-keyword">then</span>
    <span class="hljs-comment"># if the file is not empty, execute it</span>
    chmod +x script.sh
    ./script.sh
    m5 <span class="hljs-built_in">exit</span>
<span class="hljs-keyword">fi</span>
<span class="hljs-comment"># otherwise, drop to the terminal</span>
</code></pre>
<p>readfile&#x91CC;&#x9762;&#x7684;&#x5185;&#x5BB9;&#x5C31;&#x662F;&#x5728;&#x5168;&#x7CFB;&#x7EDF;&#x8FD0;&#x884C;&#x811A;&#x672C;&#x4E2D;&#x6307;&#x5B9A;&#x7684;commad&#xFF0C;&#x89C1;<a href="gem5_fs.html">Gem5 &#x5168;&#x7CFB;&#x7EDF;&#x6A21;&#x5F0F;&#x5165;&#x95E8;</a>&#xFF1A;</p>
<p>readfile_contents&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x6700;&#x7EC8;&#x4F1A;&#x53D8;&#x4E3A;readfile&#x3002;&#x8FD9;&#x4E2A;&#x5728;m5out/readfile&#x4E2D;&#x4E5F;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x3002;&#x56E0;&#x6B64;&#x6839;&#x636E;&#x8BE5;&#x811A;&#x672C;&#xFF0C;&#x5982;&#x679C;readfile&#x7684;&#x5185;&#x5BB9;&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x5219;&#x6267;&#x884C;&#x91CC;&#x9762;&#x7684;&#x547D;&#x4EE4;&#xFF0C;&#x7136;&#x540E;&#x9000;&#x51FA;&#x3002;&#x5426;&#x5219;&#x5C31;&#x8F6C;&#x5230;&#x7EC8;&#x7AEF;&#xFF0C;&#x8FD9;&#x4E5F;&#x89E3;&#x91CA;&#x4E86;&#x6CE8;&#x91CA;&#x6389;readfile_contents&#x540E;&#xFF0C;&#x5168;&#x7CFB;&#x7EDF;&#x6A21;&#x62DF;&#x5668;&#x7684;&#x884C;&#x4E3A;&#x3002;&#xFF08;&#x5728;<a href="gem5_fs.html">Gem5 &#x5168;&#x7CFB;&#x7EDF;&#x6A21;&#x5F0F;&#x5165;&#x95E8;</a>&#x7684;&#x6700;&#x540E;&#x4E00;&#x5F20;&#x622A;&#x56FE;&#x4E2D;&#xFF09;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202304121710858.png" alt="image-20230412171014779"></p>
<h4 id="&#x2463;npb-installsh">&#x2463;npb-install.sh</h4>
<p>&#x8BE5;&#x811A;&#x672C;&#x7684;&#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x662F;&#x7F16;&#x8BD1;&#x4F60;&#x7684;&#x7A0B;&#x5E8F;&#xFF0C;&#x8BF7;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x7A0B;&#x5E8F;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x3002;</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/sh
</span>
<span class="hljs-comment"># Copyright (c) 2020 The Regents of the University of California.</span>
<span class="hljs-comment"># SPDX-License-Identifier: BSD 3-Clause</span>

<span class="hljs-comment"># install build-essential (gcc and g++ included) and gfortran</span>

<span class="hljs-comment">#Compile NPB</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;12345&quot;</span> | sudo apt-get install build-essential gfortran

<span class="hljs-built_in">cd</span> /home/gem5/NPB3.3-OMP/

mkdir bin

make suite HOOKS=1
</code></pre>
<h2 id="3&#x3001;&#x521B;&#x5EFA;&#x8FD0;&#x884C;&#x811A;&#x672C;">3&#x3001;&#x521B;&#x5EFA;&#x8FD0;&#x884C;&#x811A;&#x672C;</h2>
<p>npb&#x7684;&#x8FD0;&#x884C;&#x793A;&#x4F8B;&#x811A;&#x672C;&#x4F4D;&#x4E8E; gem5 &#x5B58;&#x50A8;&#x5E93;&#x7684;&#x4EE5;&#x4E0B;&#x76EE;&#x5F55;&#x4E2D;&#xFF1A;gem5/configs/example/gem5_library/x86-npb-benchmarks.py&#x3002;&#x9700;&#x8981;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x3002;&#x5176;&#x4E2D;&#xFF0C;&#x4E0D;&#x80FD;&#x518D;&#x4F7F;&#x7528;<code>disk_image=Resource()</code></p>
<pre><code class="lang-python">board.set_kernel_disk_workload(
    kernel=Resource(<span class="hljs-string">&quot;x86-linux-kernel-4.19.83&quot;</span>),
    disk_image=Resource(<span class="hljs-string">&quot;x86-npb&quot;</span>),
    readfile_contents=command,
)
</code></pre>
<p>&#x8BF7;&#x5C06;&#x5176;&#x4FEE;&#x6539;&#x4E3A;&#xFF1A;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x521A;&#x521A;&#x901A;&#x8FC7;Packer&#x751F;&#x6210;&#x7684;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;root&#x6302;&#x8F7D;&#x7684;&#x5206;&#x533A;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> gem5.resources.resource <span class="hljs-keyword">import</span>  CustomDiskImageResource

board.set_kernel_disk_workload(
    kernel=Resource(<span class="hljs-string">&quot;x86-linux-kernel-5.4.49&quot;</span>,),
    disk_image=CustomDiskImageResource(<span class="hljs-string">&quot;/home/jiangfang/workspace/gem5_home/afterimage/disk-image/afterimage/afterimage-image/afterimage&quot;</span>,<span class="hljs-string">&quot;1&quot;</span>),
    readfile_contents=command,
)
</code></pre>
<p>&#x8FD8;&#x9700;&#x8981;&#x6839;&#x636E;&#x4F60;&#x7A0B;&#x5E8F;&#x7684;&#x9700;&#x8981;&#xFF0C;&#x4FEE;&#x6539;&#x76F8;&#x5E94;&#x7684;common&#x547D;&#x4EE4;&#xFF1A;</p>
<p>&#x5728;&#x7B2C;&#x4E09;&#x884C;&#xFF0C;&#x8FD0;&#x884C;&#x76F8;&#x5E94;&#x7684;&#x653B;&#x51FB;&#x4EE3;&#x7801;</p>
<pre><code class="lang-python">command = <span class="hljs-string">&quot;m5 exit;&quot;</span> \
        + <span class="hljs-string">&quot;echo &apos;This is running on Timing CPU cores. AfterImage:&apos;;&quot;</span> \
        +<span class="hljs-string">&quot;/home/gem5/prefetching_attack/prefetching_poc/V1.A/main;&quot;</span>\
        +<span class="hljs-string">&quot;echo &apos;AfterImage run over:&apos;;&quot;</span>\
        + <span class="hljs-string">&quot;sleep 1;&quot;</span> \
        + <span class="hljs-string">&quot;m5 exit;&quot;</span>
</code></pre>
<h2 id="4&#x3001;&#x8FD0;&#x884C;">4&#x3001;&#x8FD0;&#x884C;</h2>
<p>&#x5BF9;&#x4E8E;npb&#x800C;&#x8A00;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x65B9;&#x5F0F;&#x8FDB;&#x884C;&#x8FD0;&#x884C;&#xFF1A;</p>
<pre><code># In the gem5 directory
build/X86/gem5.opt \
configs/example/gem5_library/x86-npb-benchmarks.py \
--benchmark &lt;benchmark_program&gt; \
--size &lt;class_of_the_benchmark&gt;
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="gem5_fs.html" class="navigation navigation-prev " aria-label="Previous page: X86 全系统模式模拟">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../ysyx/FangCore/1单周期CPU.html" class="navigation navigation-next " aria-label="Next page: 单周期CPU实现">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"自定义磁盘镜像","level":"4.2","depth":1,"next":{"title":"单周期CPU实现","level":"5.1","depth":1,"path":"ysyx/FangCore/1单周期CPU.md","ref":"ysyx/FangCore/1单周期CPU.md","articles":[]},"previous":{"title":"X86 全系统模式模拟","level":"4.1","depth":1,"path":"gem5/gem5_fs.md","ref":"gem5/gem5_fs.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"gem5/custom_disk_img.md","mtime":"2023-04-12T09:23:07.791Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-04-12T09:28:35.525Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

